import 'package:appflutterhomeschool/provider/provider_widget.dart';
import 'package:appflutterhomeschool/res/colors.dart';
import 'package:appflutterhomeschool/res/styles.dart';
import 'package:appflutterhomeschool/route/application.dart';
import 'package:appflutterhomeschool/route/routes.dart';
import 'package:appflutterhomeschool/ui/widgets/button_widget.dart';
import 'package:appflutterhomeschool/ui/widgets/my_app_bar.dart';
import 'package:appflutterhomeschool/ui/widgets/notice/notice_tab_widget.dart';
import 'package:appflutterhomeschool/ui/widgets/widgets.dart';
import 'package:appflutterhomeschool/view_model/academic_sentiment/operation_details_view_model.dart';
import 'package:appflutterhomeschool/view_model/my_app_view_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';

///用户： ninetailedfox
///时间： 2020/7/5
///邮箱： 1037438704@qq.com
///功能： 作业详情
class OperationDetailsPage extends StatelessWidget {
  final id;

  OperationDetailsPage({this.id});

  @override
  Widget build(BuildContext context) {
    MyAppViewModel myAppViewModel = Provider.of<MyAppViewModel>(context);
    return ProviderWidget<OperationDetailsViewModel>(
      model: OperationDetailsViewModel(context, id),
      onModelReady: (value) => value.initView(),
      builder: (context, viewModel, child) {
        return Scaffold(
          backgroundColor: Colours.gray_f6,
          appBar: MyAppBar2(title: "作业详情"),
          body: Stack(
            children: [
              Positioned(
                top: 0,
                bottom: !myAppViewModel.identity ? 115 : 0,
                right: 0,
                left: 0,
                child: SingleChildScrollView(
                  child: Column(
                    children: <Widget>[
                      viewModel.parentGetHomeworkList != null
                          ? Container(
                              padding: EdgeInsets.only(top: 5),
                              child: Text(
                                viewModel.parentGetHomeworksModel
                                    .getTitleStatus(viewModel.identity),
                                style: TextStyles.textRed34,
                              ),
                              alignment: Alignment.center,
                            )
                          : Container(),
                      Container(
                        margin: EdgeInsets.only(
                            left: ScreenUtil().setWidth(35),
                            right: ScreenUtil().setWidth(35),
                            top: ScreenUtil().setWidth(35)),
                        decoration: BoxDecoration(
                            color: Colors.white,
                            borderRadius: BorderRadius.circular(10)),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: <Widget>[
                            Padding(
                              padding: EdgeInsets.only(
                                  left: ScreenUtil().setWidth(35),
                                  right: ScreenUtil().setWidth(35),
                                  top: ScreenUtil().setWidth(35)),
                              child: Row(
                                children: <Widget>[
                                  Container(
                                      margin: EdgeInsets.only(right: 5),
                                      padding: EdgeInsets.only(
                                          top: 1, bottom: 1, left: 3, right: 3),
                                      decoration: BoxDecoration(
                                          color: Colors.blue[50],
                                          borderRadius:
                                              BorderRadius.circular(3)),
                                      child: Text(
                                          viewModel?.parentGetHomeworksModel
                                                  ?.subject ??
                                              "",
                                          style: TextStyles.textBlue30)),
                                  Expanded(
                                      child: Text(
                                          viewModel?.parentGetHomeworksModel
                                                  ?.title ??
                                              "",
                                          style: TextStyles.textDarkBold43)),
                                ],
                              ),
                            ),
                            Container(
                              alignment: Alignment.centerLeft,
                              padding: EdgeInsets.only(
                                  left: ScreenUtil().setWidth(35),
                                  right: ScreenUtil().setWidth(35),
                                  top: ScreenUtil().setWidth(35)),
                              child: myAppViewModel.identity
                                  ? Text(
                                      "发布于：${viewModel.parentGetHomeworksModel?.monthDay}",
                                      style: TextStyles.textGray30)
                                  : ItemTopWidget(
                                      className: viewModel
                                              .parentGetHomeworksModel
                                              ?.teacherName ??
                                          "",
                                      textContent:
                                          "${viewModel.parentGetHomeworksModel?.publishTime}",
                                      visibility: false,
                                    ),
                            ),
                            Container(
                              padding:
                                  EdgeInsets.all(ScreenUtil().setWidth(35)),
                              child: Text(
                                viewModel?.parentGetHomeworksModel?.content ??
                                    "",
                                style: TextStyles.textContent31,
                              ),
                            ),
                            ListViewWidget(
                              shanchuFujian: false,
                              setWidth: 100,
                              type: 1,
                              listImage: viewModel.imageUrlList,
                              onTapIndex: (index) {},
                            ),
                            Visibility(
                              visible: !myAppViewModel.identity,
                              child: Container(
                                margin: EdgeInsets.only(
                                    left: ScreenUtil().setWidth(43),
                                    bottom: ScreenUtil().setWidth(43)),
                                width: ScreenUtil().setWidth(280),
                                height: ScreenUtil().setWidth(73),
                                child: ButtonWidget().ellipseFrameButton(
                                    textStyle: TextStyles.textBlue30,
                                    buttonName: "查看系统作业",
                                    borderSideColor: Colors.blue,
                                    widthDouble: ScreenUtil().setWidth(243),
                                    heightDouble: ScreenUtil().setWidth(115),
                                    onPressed: () {
                                      //进入答题卡
                                      Application().navigatePushToPage(
                                          context, Routes.answerSheetPage, {
                                        "id": viewModel
                                            ?.parentGetHomeworksModel?.id,
                                      });
                                    }),
                              ),
                            ),
                          ],
                        ),
                      ),
                      Visibility(
                        visible: myAppViewModel.identity,
                        child: Container(
                          color: Colors.white,
                          margin: EdgeInsets.only(top: 10),
                          child: NoticeTabWidget(
                            rightUnread: false,
                            openScreen: true,
                            listTab: viewModel.listTab,
                            getIndex: (index) {
                              viewModel.tapModelOnTap(index);
                            },
                          ),
                        ),
                      ),
                      Visibility(
                        visible: myAppViewModel.identity,
                        child: viewModel.parentGetHomeworkList != null &&
                                viewModel.parentGetHomeworkList?.length != 0
                            ? ListView.builder(
                                physics: NeverScrollableScrollPhysics(),
                                shrinkWrap: true,
                                itemCount:
                                    viewModel.parentGetHomeworkList?.length,
                                itemBuilder: (context, index) {
                                  return ItemNameWidget(
                                    remindOnTap: () =>
                                        viewModel.remindOnTap(index),
                                    title: viewModel
                                        ?.parentGetHomeworkList[index]
                                        ?.teacherName,
                                    content: viewModel
                                        ?.parentGetHomeworkList[index].monthDay,
                                    visibleStars: viewModel.getTabIndex == 1,
                                    visibleRemind: viewModel.getTabIndex == 2,
                                    visibleJump: viewModel.getTabIndex != 2,
                                    onTap: () {
                                      Application().navigatePushToPage(
                                          context, Routes.operationDetailsPage, {
                                        "id": viewModel
                                            ?.parentGetHomeworkList[index]?.id
                                      });
                                    },
                                  );
                                })
                            : Container(
                                margin: EdgeInsets.only(top: 100),
                                child: Text("暂无数据"),
                              ),
                      ),
                    ],
                  ),
                ),
              ),
              Positioned(
                bottom: 0,
                left: 0,
                right: 0,
                child: Visibility(
                  visible: !myAppViewModel.identity,
                  child: Row(
                    children: [
                      Expanded(
                        child: ButtonWidget().rectangleButtonWidget(
                            buttonName: "有疑问",
                            bgColor: Colors.white,
                            textStyle: TextStyles.textDark30,
                            onPressed: () {}),
                      ),
                      viewModel?.parentGetHomeworksModel != null
                          ? Visibility(
                              visible: viewModel?.parentGetHomeworksModel
                                  ?.getTitleBool(viewModel.identity),
                              child: Expanded(
                                child: ButtonWidget().rectangleButtonWidget(
                                  buttonName: "提交作业",
                                  bgColor: Colors.blue,
                                  textStyle: TextStyles.textWhite30,
                                  onPressed: () => Application()
                                      .navigatePushToPage(
                                          context, Routes.answerDisplayPage, {
                                    "pageTag": 0,
                                    "id": id,
                                  }),
                                ),
                              ),
                            )
                          : Container(),
                    ],
                  ),
                ),
              )
            ],
          ),
        );
      },
    );
  }
}
